"""
def里面只看到一个yield关键字表示就是协程
协程之间执行任务按照一定顺序交替执行
"""

# 通过协程实现多任务
import time


def work1():
    while True:
        print("----work1---")
        yield  # return + 暂停
        time.sleep(0.5)


def work2():
    while True:
        print("----work2---")
        yield  # return + 暂停
        time.sleep(0.5)


def main():
    w1 = work1()
    w2 = work2()
    while True:
        next(w1)  # 获取下一个
        next(w2)


if __name__ == "__main__":
    main()